package system

import (
	route_conf "svntool/application/conf"
	functions_bootstrap "svntool/application/functions"
	"svntool/application/models/roles"
	myos "svntool/application/models/util/os"
	"svntool/db/tables"
	db_bootstrap "svntool/system/models/bootstrap"
	routes_bootstrap "svntool/system/routers"

	"github.com/astaxie/beego"
)

/**
 * 启动引导程序，初始化内容包括 数据库/路由/函数等
 */

//初始化配置文件
func initConf() {
	beego.LoadAppConfig("ini", "application/conf/app.conf")
}

//初始化DB
func initDb() {
	db_bootstrap.Init()
	roles_model := roles.RoleBuilder{}
	roles_model.InitRoles()
}

//初始化路由
func initRoute() {
	bootstrap := routes_bootstrap.Bootstrap{route_conf.Router_arr, route_conf.Filter_arr}
	bootstrap.Init()
}

//初始化函数
func initFunc() {
	bootstrap := functions_bootstrap.Bootstrap{}
	bootstrap.Init()
}

//初始化系统
func initSystem() {
	myos, artiture, err := myos.Info()
	if err == nil {
		//保存系统信息
		config := tables.Config{}
		config.SaveSystemInfo(myos, artiture)
	}
}

func init() {
	initConf()
	initDb()
	initFunc()
	initRoute()
	initSystem()
}
